layui.use('table', function () {
    var table = layui.table;
    table.render({
        elem: '#test'
        , url: '/Person/UserPageList'
        , defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
        }]
        , title: '用户数据表'
        , cols: [[
            { type: 'checkbox', fixed: 'left' }
            , { field: 'UserId', title: 'ID', width: 200, fixed: 'left', unresize: true, sort: true }
            , { field: 'UserName', title: '用户名', width: 250, edit: 'text' }
            , { field: 'Password', title: '密码', width: 250 }
            , { field: 'EmployeeName', title: '姓名', width: 250 }
            , { field: 'DepartId', title: '部门Id', width: 250 }
            , { field: 'Status', title: '状态', width: 250 }
            , { fixed: 'right', title: '操作', toolbar: '#barDemo', width: 400 }
        ]]
        , page: true
        , id: 'testReload'
    });
   
    table.on('tool(test)', function (obj) {
        var data = obj.data;
        var id = data.UserId;
        //console.log(obj)
        if (obj.event === 'del') {
            layer.confirm('真的删除行么', function (index) {
                $.ajax({
                    type: "post",
                    url: "/Person/Delect?id=" + id,
                    success: function (operateResult) {
                        if (operateResult.success) {
                            layer.msg('删除成功!', { icon: 6, time: 1000 });
                            obj.del();
                            layer.close(index);
                        } else {
                            layer.msg('删除失败!', { icon: 6, time: 1000 });
                        }
                    }
                })

            });
        } else if (obj.event === 'edit') {
            var Id = data.UserId;
            $.ajax({
                type: "post",
                url: "/Person/Update?id=" + Id,
                success: function (responseResult) {
                    if (responseResult.success) {
                        window.location.href = "/Home/Person_Update";
                    } else {
                        layer.msg('编辑失败!', { icon: 6, time: 1000 });
                    }
                }
            })
        }
        
    });
})
//列表刷新
function TableReload() {
    var table = layui.table;
    //获取页面管理员名称和时间
    var username = $("#user").val();
    //上述方法等价于
    table.reload('testReload', {
        where: { //设定异步数据接口的额外参数，任意设
            username: username,
        }
    });
};
//查询点击事件
$("#check").click(function () {

    TableReload();

});


